package com.flowerplus.store.app.login;

import android.app.Activity;

import com.flowerplus.store.api.ApiService;
import com.flowerplus.store.app.RxDisposable;
import com.flowerplus.store.common.data.http.ApiSubscriber;
import com.flowerplus.store.common.data.injector.PerActivity;
import com.flowerplus.store.common.structure.mvp.AbsBasePresenter;
import com.flowerplus.store.models.result.ResultBean;

import javax.inject.Inject;

/**
 * Created by dell - on 2018/1/18.
 */
@PerActivity
public class MobileInputPresenter extends AbsBasePresenter implements MobileInputContract.Presenter {

    private ApiService mApiService;
    private MobileInputContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public MobileInputPresenter(ApiService apiService,
                                Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onDestroy() {
        mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }

    @Override
    public void onCreate(MobileInputContract.View view) {
        this.mView = view;
    }




    @Override
    public void checkPhone(String phone) {
        mRxDisposable.add(mApiService.checkMobile( phone)
                .subscribe(new ApiSubscriber<ResultBean>(mView) {
                    @Override
                    public void next(ResultBean bean) {
                        mView.checkPhoneSuccess();
                    }
                }));
    }
}
